Optional Sprites.f

Requires Tools
Requires Quicksort
Requires SORA\Motifs
Requires SORA\Vertices
Requires SORA\Vbufs
Requires SORA\Images
Only Forth Definitions

0 Value (flip)

icode xswap
   0 [ebp] ecx mov
   8 [ebp] eax mov
   ecx 8 [ebp] mov
   eax 0 [ebp] mov
   ret end-code

icode yswap
   ebx ecx mov
   4 [ebp] ebx mov
   ecx 4 [ebp] mov
   ret end-code

{
: xflip   xswap 2>r 1 0 2- 2r> 1 0 2- ;
: yflip   yswap 2>r 0 1 2- 2r> 0 1 2- ;
: xyflip   1 1 2- 2swap ; \ 1 1 2- ;
}

\ :macro rectarea      dup >r 2h@  r> 4 + 2h@ 2over 2+ ;

\ create flips   0 , ' xflip , ' yflip , ' xyflip ,
 create flips   0 , ' xswap , ' yswap , ' 2swap ,

:macro ?flip   cells flips + @ execute ;

:macro  area   2over 2+ ;

-? 0 transform.ref t
: slow-sprite  ( subimage transform -- )
   to t locals| spr  |
   spr rect.@ area
   t.pos.z.@
   spr 8 + h@ negate  spr 10 + h@ negate  \ t 2transform
   spr 4 +  2h@  area  (flip) ?flip
   t transformed-quad2d ;

: fast-sprite  ( subimage transform -- )
   to t locals| spr |
   spr 2h@
   spr 4 + 2h@ 2over 2+
   t.pos.z.@
   t.pos.x.2@   spr 8 + 2h@ 2-   spr 4 + 2h@ 2over 2+
   quad2d ;

method: subimage.sprite  ( transform -- )
   to t
   t.color.@ to vcolor  roll.@   t.scale.x.@  or  (flip) or  if
      this t slow-sprite else this t fast-sprite then ;

